home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SWAG9605.DDD / 0081_Determining the Cursor Position in Memo.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-05-31  |  1.1 KB  |  29 lines

  1. {
  2. > Is it possible to get the position of the cursor (lines and columns)
  3. > for a memo field. If not, is there a component somewhere that will
  4. > let me do this.
  5.  
  6. I had the same problem with an editor I wrote called TabNotes.  You can get this from:
  7.  
  8.  http://www.reusable.com
  9.  
  10. Anyway, here is how I got the info for a descendant of TMemo called TNotePad:
  11.  
  12. {The following two methods are used to get row/column coordinates.     }
  13. {There are no messages that explicitly provide column information but the}
  14. {EM_GETSEL message provides the position of the caret if a selection is  }
  15. {not currently active. When text is selected the caret can be positioned at }
  16. {the beginning or the end of the selection depending how it was selected.}
  17. {Thus these methods may be slightly inaccurate while text is selected. }
  18.  
  19. function  TNotePad.GetColumn: SmallInt;
  20. begin
  21.   Result := (SelStart+SelLength) -        {Assume that caret is at end of Selection}
  22.             Perform(EM_LINEINDEX, -1, 0); {Method version of SendMessage}
  23. end;
  24.  
  25. function  TNotePad.GetRow: SmallInt;
  26. begin
  27.   Result := LongRec(Perform(EM_LINEFROMCHAR, -1, 0)).Lo; {Get Low word}
  28. end;
  29.